<div id="maincontent">
	<div id="content">
    <div class="box1">
      <h1>Page Loadtimes</h1>
      
		<?php
	  


		unset($row);
		$sql = "SELECT `time`, `domainLookupEnd`, `responseEnd`, `domComplete` FROM `stats_loadtime` WHERE `time`>DATE_SUB(now(), INTERVAL 180 MINUTE) ORDER BY `time` ASC";
		$row = $db->getAll_assoc($sql);
		for($i=0; $i<count($row); $i++) {
			$aAllKeyLogsAvgDonmainLookupLIVE[date('Y,m-1,d,H,i,s',strtotime($row[$i]['time']))] =		$row[$i]['domainLookupEnd'];
			$aAllKeyLogsAvgResponseTimeLIVE[date('Y,m-1,d,H,i,s',strtotime($row[$i]['time']))] =		$row[$i]['responseEnd'];
			$aAllKeyLogsAvgCompleteTimeLIVE[date('Y,m-1,d,H,i,s',strtotime($row[$i]['time']))] =		$row[$i]['domComplete'];
		}

		

		unset($row);
		$sql = "SELECT `time`, AVG(`domainLookupEnd`) AS AvgDonmainLookup, AVG(`responseEnd`) AS AvgResponseTime, AVG(`domComplete`) AS AvgCompleteTime FROM `stats_loadtime` WHERE `time`>DATE_SUB(now(), INTERVAL 4 DAY) GROUP BY DATE(`time`), HOUR(`time`)";
		$row = $db->getAll_assoc($sql);
		for($i=0; $i<count($row); $i++) {
			$aAllKeyLogsAvgDonmainLookup[date('Y,m-1,d,H,i,00',strtotime($row[$i]['time']))] =		$row[$i]['AvgDonmainLookup'];
			$aAllKeyLogsAvgResponseTime[date('Y,m-1,d,H,i,00',strtotime($row[$i]['time']))] =		$row[$i]['AvgResponseTime'];
			$aAllKeyLogsAvgCompleteTime[date('Y,m-1,d,H,i,00',strtotime($row[$i]['time']))] =		$row[$i]['AvgCompleteTime'];
		}
		
		
		
		unset($row);
		$sql = "SELECT `time`, AVG(`domainLookupEnd`) AS AvgDonmainLookup, AVG(`responseEnd`) AS AvgResponseTime, AVG(`domComplete`) AS AvgCompleteTime FROM `stats_loadtime` WHERE `time`>DATE_SUB(now(), INTERVAL 120 DAY) GROUP BY DATE(`time`) ORDER BY `time` ASC";
		$row = $db->getAll_assoc($sql);
		for($i=0; $i<count($row); $i++) {
			$aAllKeyLogsAvgDonmainLookup2[date('Y,m-1,d',strtotime($row[$i]['time']))] =	$row[$i]['AvgDonmainLookup'];
			$aAllKeyLogsAvgResponseTime2[date('Y,m-1,d',strtotime($row[$i]['time']))] =		$row[$i]['AvgResponseTime'];
			$aAllKeyLogsAvgCompleteTime2[date('Y,m-1,d',strtotime($row[$i]['time']))] =		$row[$i]['AvgCompleteTime'];
		}

		?>
		<script src="/js/highcharts/js/highcharts.js" type="text/javascript"></script>
		
		<script type="text/javascript">
			/* <![CDATA[ */
			var chart;
			var chart1;
			var chart2;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container0',
						zoomType: 'x',
						spacingRight: 20
					},
					title: {
						text: 'LIVE loadtimes (last 3 hours)'
					},
					subtitle: {
						text: document.ontouchstart === undefined ?
						'Drag your finger over the plot to zoom in' :
						'Drag your finger over the plot to zoom in'
					},
					xAxis: {
						type: 'datetime',
						maxZoom: 14 * 24 * 3600, // fourteen days
						title: {
							text: null
						}
					},
					yAxis: {
						title: {
							text: 'Loadtime in seconds'
						},
						min: 0.6,
						startOnTick: false,
						showFirstLabel: false
					},
					tooltip: {
						shared: true               
					},
					legend: {
						enabled: true,
						layout: "vertical"
					},
					plotOptions: {
						area: {
							fillColor: {
								linearGradient: [0, 0, 0, 300],
								stops: [
								[0, Highcharts.getOptions().colors[0]],
								[1, 'rgba(2,0,0,0)']
								]
							},
							lineWidth: 1,
							marker: {
								enabled: false,
								states: {
									hover: {
										enabled: true,
										radius: 5
									}
								}
							},
							shadow: false,
							states: {
								hover: {
									lineWidth: 1                  
								}
							}
						}
					},
					series: [{
						name: 'Loadtime complete',
						data: [
							<?php
							foreach($aAllKeyLogsAvgCompleteTimeLIVE AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					},{
						name: 'Responsetime',
						data: [
							<?php
							foreach($aAllKeyLogsAvgResponseTimeLIVE AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					},{
						name: 'DNS Lookup',
						data: [
							<?php
							foreach($aAllKeyLogsAvgDonmainLookupLIVE AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					}]
				});
				chart1 = new Highcharts.Chart({
					chart: {
						renderTo: 'container1',
						zoomType: 'x',
						spacingRight: 20
					},
					title: {
						text: 'Average loadtime (last 4 days)'
					},
					subtitle: {
						text: document.ontouchstart === undefined ?
						'Drag your finger over the plot to zoom in' :
						'Drag your finger over the plot to zoom in'
					},
					xAxis: {
						type: 'datetime',
						maxZoom: 14 * 24 * 3600, // fourteen days
						title: {
							text: null
						}
					},
					yAxis: {
						title: {
							text: 'Ladezeit in Sekunden'
						},
						min: 0.6,
						startOnTick: false,
						showFirstLabel: false
					},
					tooltip: {
						shared: true               
					},
					legend: {
						enabled: true,
						layout: "vertical"
					},
					plotOptions: {
						area: {
							fillColor: {
								linearGradient: [0, 0, 0, 300],
								stops: [
								[0, Highcharts.getOptions().colors[0]],
								[1, 'rgba(2,0,0,0)']
								]
							},
							lineWidth: 1,
							marker: {
								enabled: false,
								states: {
									hover: {
										enabled: true,
										radius: 5
									}
								}
							},
							shadow: false,
							states: {
								hover: {
									lineWidth: 1                  
								}
							}
						}
					},
					series: [{
						name: 'Loadtime complete',
						data: [
							<?php
							foreach($aAllKeyLogsAvgCompleteTime AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					},{
						name: 'Responsetime',
						data: [
							<?php
							foreach($aAllKeyLogsAvgResponseTime AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					},{
						name: 'DNS Lookup',
						data: [
							<?php
							foreach($aAllKeyLogsAvgDonmainLookup AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					}]
				});
				chart2 = new Highcharts.Chart({
					chart: {
						renderTo: 'container2',
						zoomType: 'x',
						spacingRight: 20
					},
					title: {
						text: 'Average loadtime (last 120 days)'
					},
					subtitle: {
						text: document.ontouchstart === undefined ?
						'Drag your finger over the plot to zoom in' :
						'Drag your finger over the plot to zoom in'
					},
					xAxis: {
						type: 'datetime',
						maxZoom: 14 * 24 * 3600, // fourteen days
						title: {
							text: null
						}
					},
					yAxis: {
						title: {
							text: 'Loadtime in seconds'
						},
						min: 0.6,
						startOnTick: false,
						showFirstLabel: false
					},
					tooltip: {
						shared: true               
					},
					legend: {
						enabled: true,
						layout: "vertical"
					},
					plotOptions: {
						area: {
							fillColor: {
								linearGradient: [0, 0, 0, 300],
								stops: [
								[0, Highcharts.getOptions().colors[0]],
								[1, 'rgba(2,0,0,0)']
								]
							},
							lineWidth: 1,
							marker: {
								enabled: false,
								states: {
									hover: {
										enabled: true,
										radius: 5
									}
								}
							},
							shadow: false,
							states: {
								hover: {
									lineWidth: 1                  
								}
							}
						}
					},
					series: [{
						name: 'Loadtime complete',
						data: [
							<?php
							foreach($aAllKeyLogsAvgCompleteTime2 AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					},{
						name: 'Responsetime',
						data: [
							<?php
							foreach($aAllKeyLogsAvgResponseTime2 AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					},{
						name: 'DNS Lookup',
						data: [
							<?php
							foreach($aAllKeyLogsAvgDonmainLookup2 AS $key => $value) {
								echo "[Date.UTC(".$key."),".$value."], ";
							}
							?>
						]
					}]
				});
			});
			/* ]]> */
		</script>
		
		<div id="charttext"><br></div>
		<div id="container0" style="width:830px;height:408px;margin-bottom:15px;"></div>
		<div id="container1" style="width:830px;height:408px;margin-bottom:15px;"></div>
		<div id="container2" style="width:830px;height:408px;margin-bottom:15px;"></div>
		<div style="clear:both;"></div>



    </div>
  </div>
</div>
